﻿namespace Blaze.Editor
{
    using UnityEditor;
    using UnityEngine;

    /// <summary>
    /// Blaze编辑器资源管理。
    /// </summary>
    public static class BlazeEditorResources
    {
        /// <summary>
        /// 在Blaze编辑器资源目录中创建指定的资源。
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="path"></param>
        public static void Create(Object asset, string path)
        {
            AssetDatabase.CreateAsset(asset, getAssetRelativePath(path));
        }

        /// <summary>
        /// 加载Blaze编辑器资源。
        /// </summary>
        /// <typeparam name="T">资源类型</typeparam>
        /// <param name="path">资源相对路径</param>
        public static T Load<T>(string path) where T : Object
        {
            var asset = (T) AssetDatabase.LoadAssetAtPath(getAssetRelativePath(path), typeof (T));
            if (asset != null)
                asset.hideFlags = HideFlags.HideAndDontSave;
            return asset;
        }

        private static string getAssetRelativePath(string relativePath)
        {
            return "Assets/Blaze/Editor/EditorResources/" + relativePath;
        }
    }
}